package com.exam.sacrifice.viewmodel;

import androidx.lifecycle.ViewModel;

import com.exam.commonbiz.net.BaseObserver;
import com.exam.commonbiz.net.BaseResponse;
import com.exam.commonbiz.net.ExceptionHandle;
import com.exam.commonbiz.net.XApi;
import com.exam.sacrifice.api.ApiService;
import com.exam.sacrifice.ui.bean.BaiJiaXingListReq;
import com.exam.sacrifice.ui.bean.BaiJiaXingListRes;

import org.json.JSONException;
import org.json.JSONObject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class BaiJiaXingViewModel extends ViewModel {

    private IBaiJiaXingCallBack baiJiaXingCallBack;

    public void setBaiJiaXingCallBack(IBaiJiaXingCallBack baiJiaXingCallBack) {
        this.baiJiaXingCallBack = baiJiaXingCallBack;
    }

    public void surnamePage(int pageIndex, String keyword) {

        BaiJiaXingListReq baiJiaXingListReq = new BaiJiaXingListReq();
        baiJiaXingListReq.keyword = keyword;
        baiJiaXingListReq.pageSize = 10;
        baiJiaXingListReq.pageIndex = pageIndex;

        XApi.get(ApiService.class)
                .surnamePage(baiJiaXingListReq)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaiJiaXingListRes>() {

                    @Override
                    public void onStart() {

                    }

                    @Override
                    public void onSuccess(BaseResponse<BaiJiaXingListRes> response) {
                        if (baiJiaXingCallBack != null) {
                            baiJiaXingCallBack.onBaiJiaXingList(response.getData());
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponeThrowable responeThrowable) {

                    }

                    @Override
                    public void onFinish() {

                    }

                });
    }
}
